import axios from 'axios'
import nprogress from 'nprogress' // 引入进度条
import "nprogress/nprogress.css" // 引入相关进度条的样式

const request = axios.create({
  timeout: 5000
})

request.interceptors.request.use(
  config => {
    config.headers['Content-Type'] = 'application/json;charset=utf-8'
    nprogress.start()
    return config
  }, error => {
    return Promise.reject(error)
  }
)

request.interceptors.response.use(
  response => {
    nprogress.end()
    return  response.data
  },
  error => {
    return Promise.reject(error)
  }
)

export default request
